<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();//获得项目的根目录，上下文路径
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>" />
<meta charset="UTF-8">
<title>Detail.jsp</title>
<link rel="stylesheet" href="css/bootstrap.css">
<script src="js/jquery.js"></script>
<script src="js/bootstrap.js"></script>
<script type="text/javascript" src="js/detail.js"></script>
<script>
	//请求所有的帖子明细表信息	
	$(function() {
				$.ajax({
					url : "st/getAll",
					data : {},
					dataType : "json",
					type : "get",
					success : function(res) {
						console.log(res);
						var table = $("table");
						var tr = "<tr><th>帖子ID</th><th>标题</th><th>作者</th><th>发布时间</th><th>回复次数</th></tr>"
						table.append(tr);
						$(res).each(
								function() {
									var tr = "<tr>" + "<td>" + this.id
											+ "</td>" + "<td>" + this.title
											+ "</td>" + "<td>" + this.author
											+ "</td>" + "<td>" + this.createDate
											+ "</td>" + "<td>" + this.replyCount
											+ "</td>" + "</tr>";
									table.append(tr);
								});
					},
					error : function(res) {
						console.log(res)
					}
			});
	});
	
	//获得所有讨论版区分类表的信息
	$(function() {
		$.get(
			"sort/getAllSorts",
			function(res) {
				var sort_id = $("#sort_id");
				var option = "<option value='0'>--请选择--</option>";
				sort_id.append(option);
				var r = "${SORT_ID}";//获得model中的属性值，默认是0
				$(res).each(function() {
					if (this.id == r) {
						var option = "<option value='"+this.id+"' selected>"+ this.name+ "</option>";
					} else {
						var option = "<option value='"+this.id+"'>"+ this.name+ "</option>";
					}
					sort_id.append(option);
				});
			},'json');
	});
	
</script>
</head>
<body>
	<span>讨论版区：</span> <select id="sort_id" class="btn btn-primary"></select>
	<input type="button" value="查询" id="seacher" />
	<input type="button" value="发帖" id="addsort" />
<table class="table table-striped"></table>
</body>
</html>